package com.hqyj.controller;

import com.hqyj.pojo.Manager;
import com.hqyj.pojo.Yan_addcustomerpojo;
import com.hqyj.service.ManagerService;
import com.hqyj.service.service.YanAddCustomerService;
import org.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/houtai")
public class indexController {
    // 返回后台首页
    @Autowired
    ManagerService managerService;
    // 返回后台首页
    @RequestMapping("/index")
    public String index(ModelMap map, HttpServletRequest request){
        HttpSession session = request.getSession();
        Manager managerinfo = (Manager) session.getAttribute("managerinfo");
        //应该先调用数据的最新数据
        managerService.selectnew(managerinfo,request);
        Manager newmanagerinfo = (Manager) session.getAttribute("managerinfo");
        map.addAttribute("manager1",newmanagerinfo);
        return "index";
    }
    // 返回后台-控制后台
    @RequestMapping("/shouye")
    public String shouye(){
        return "houtai/shouye";
    }
    // 返回后台-申请记录
    @RequestMapping("/signLog")
    public String signLog(){
        return "houtai/signLog";
    }
    // 返回后台-个人客户
    @RequestMapping("/privateCustomer")
    public String gerenkehu(){return "houtai/privateCustomer";}
    //返回后台-客户总览
    @RequestMapping("/allCustomer")
    public String allCustomer(){
        return "houtai/allCustomer";
    }
    //返回后台客户申请界面-点击处理后的弹出层
    @RequestMapping("/dealApply")
    public String dealApply(){return "houtai/dealApply";}
    //返回后台-经理管理
    @RequestMapping("/managerAccount")
    public String managerAccount(){return "houtai/managerAccount";}
    //返回后台-服务记录
    @RequestMapping("/serviceList")
   public String serviceList(){return "houtai/serviceList";}
   //返回后台-日志
    @RequestMapping("/dailyRecord")
    public String dailyRecord(){return "houtai/dailyRecord";}

   @Autowired(required = false)
    YanAddCustomerService yanAddCustomerService;
    // 返回查询到的申请列表 ---YT
//    @RequestMapping("/List")
//    @ResponseBody
//    public Map<String,Object> handleCutSwitchAndKnifeGateTableData()
//    {
//        JSONArray jsonArray=new JSONArray();
//        ArrayList arrayList=new ArrayList();
//        arrayList= (ArrayList) ManagerServiceImpl.select();
//        Map<String,Object> map=new HashMap<>();
//        map.put("code",0);
//        map.put("msg","");
//        map.put("count",100);
//        map.put("data",arrayList);
//        return map;
//    }
    // 返回当前管理员的客户
    @ResponseBody
    @RequestMapping("/myList")
    public HashMap<String,Object> myList(String userName){
        List<Yan_addcustomerpojo> list = new ArrayList<>();
        list = yanAddCustomerService.getList(userName);
        HashMap<String,Object> map = new HashMap<>();
        System.out.println(list);
        map.put("code",0);
        map.put("msg","");
        map.put("count",20);
        map.put("data",list);
        return map;
    }



    //ajax登录
    @RequestMapping("/loginAjax")
    @ResponseBody
    public HashMap<String,Object> loginajax(){
        HashMap<String,Object> map = new HashMap<String, Object>();
        String info = "登录成功";
        map.put("info",info);
        return map;
    }

    //ajax测试图标是否显示
    @RequestMapping("/test")
    @ResponseBody
    public HashMap<String,Object> test(){
        HashMap<String,Object> map = new HashMap<String, Object>();
        int info = 1;
        map.put("info",info);
        return map;
    }
    @RequestMapping("/testSelect")
    @ResponseBody
    public HashMap<String,Object> testSelect(){
        HashMap<String,Object> map = new HashMap<String, Object>();
        String name = "user";
        String email = "318@qq.com";
        map.put("name",name);
        map.put("email",email);
        return map;
    }
}


